package com.feicheng.controller.wx;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Dict;
import com.feicheng.persistence.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/wx/dict")
@RestController("/wx/dict")
public class DictController {

    @Autowired
    IDictService dictService;

    @GetMapping("/info")
    public ResultInfo getDictInfo(String type) {
        JSONObject result = new JSONObject();
        JSONObject item = new JSONObject();
        QueryWrapper<Dict> qw = new QueryWrapper<>();
        qw.eq("type", type);
        qw.orderByAsc("sort");
        List<Dict> dicts = dictService.list(qw);
        result.put("dicts", dicts);
        dicts.forEach(dict -> {
            item.put(dict.getCode(), dict.getValue());
        });
        result.put(type, item);
        return ResultInfo.success(result);
    }

}
